<?php

/* @var $this yii\web\View */
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\bootstrap\ActiveForm;
use yii\widgets\LinkPager;
use yii\helpers\Url;
$this->title = '师资力量';
?>
<div class="zy_main">
	<div class="container">
    	
        <div class="zy_top_nav font14">师资力量</div>

        <div class="zy_course">
            <ul>
				<?php if($from){?>
					<li class="zmm1">
						<div class="d1 color99">教师来源：</div>
						<div class="d2"><div><a class="aH froms" href="javascript:;" type="0">全部</a>
							<?php foreach($from as $key=>$val){?>
								<a class="from" href="javascript:;" type="<?= Html::encode($val->from_id) ?>">
									<?= Html::encode($val->from_name) ?>
								</a>
							<?php } ?>
						</div></div>
					</li>
				<?php }?>
				
				<?php if($position){?>
					<li class="zmm2">
						<div class="d1 color99">教师职位:</div>
						<div class="d2"><div>
							<a class="aH positions" href="javascript:;" type="0">全部</a>
							<?php foreach($position as $key=>$val){?>
								<a class="position" href="javascript:;" type="<?= Html::encode($val->position_id) ?>">
									<?= Html::encode($val->position_name) ?>
								</a>
							<?php } ?>
						</div></div>
					</li>
				<?php }?>
            </ul>
        </div>
		<?php if($teacher) { ?>
		<div id='div'>
			<ul class="teacherList font12">
				<?php foreach($teacher as $key => $val) {?>
					<li class="t3out">
						<div class="teacherListL">
							<a title="<?= Html::encode($val['teacher_name']) ?>" href="<?php echo Url::to(['teacher/teacherinfo']);?>?teacher_id=<?= Html::encode($val['teacher_id']) ?>" class="go font12" type='<?= Html::encode($val['teacher_id']) ?>' style="width: 120px; height: 120px;">
								<img alt="" src="http://files.bwphp.com/file/image/show/120/120?path=<?= Html::encode($val['teacher_thumb']) ?>" style="width: 120px; height: 120px;">
							</a>
							<div onmouseover="this.style.cursor='hand'" style='padding-top:5px'>
								<center>
									<font size='4px' class='like<?= Html::encode($val['teacher_id']) ?>'>喜欢：  <?= Html::encode($val['like']) ?> </font>
									<span class='like' type='<?= Html::encode($val['teacher_id']) ?>'>
										<?php if($val['is_like'] == 1){?>
											<img src="<?php echo Url::to('@web/public/likes.png', true);?>" alt="" style="width: 30px;"/>
										<?php }else{ ?>
											<img src="<?php echo Url::to('@web/public/like.png', true);?>" alt="" style="width: 30px;"/>
										<?php }?>
										</span>
								</center>
							</div>
						</div>
						<div class="teacherListR">
							<p class="font20 color00 marginB14 t3out p">
								<?= Html::encode($val['teacher_name']) ?>
								<?php if($val['recommend']) { ?>
									<font color="red">推荐</font>
								<?php } ?>
								<a href="<?php echo Url::to(['teacher/teacherinfo']);?>?teacher_id=<?= Html::encode($val['teacher_id']) ?>" class="go font12" type='<?= Html::encode($val['teacher_id']) ?>'>	查看他的课程
								</a>
							</p>
							<p class="color66 marginB14"><span class="color99">来源：</span><?= Html::encode($val['from_name']) ?></p>
							<p class="color66 marginB14"><span class="color99">职位：</span><?= Html::encode($val['position_name']) ?></p>
							<p class="color66"><span class="color99">简介：</span>
								<?php 
									if(mb_strlen($val['teacher_desc'])>45){
										echo mb_substr($val['teacher_desc'],0,45,'utf-8').'...';
									}else{
										echo $val['teacher_desc'];
									}
								?>
							</p>
						</div>
					</li>
				<?php } ?>
			</ul>
			<div align="center">
				<?php echo LinkPager::widget([
					'pagination' => $pagination,
					'prevPageLabel'=>'上一页',
					'nextPageLabel'=>'下一页',
				]);?>
			</div>
		</div>
		<?php }else{ ?>
			<table id="user-table" class="table table-striped table-hover" style="height:100px">
				<tbody>
					<tr>
						<td colspan="20">
							<center><div class="empty" style="padding-top: 35px;">暂无教师记录</div></center>
						</td>
					</tr>
				</tbody>
			</table>
        <?php } ?>
    </div>
</div>

<!--不能重复喜欢弹框-->
<div class="modal fade" id="likeTwice" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm" style="top:150px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" style="font-size: 18px;">消息提示</h4>
            </div>
            <div class="modal-body">
                <section class="box-login v5-input-txt" id="box-login">
                        <center><h4 style="font-size: 18px;margin-bottom: 20px;">已喜欢过，不能重复喜欢</h4>
                        <button data-dismiss="modal"  style="width: 150px;" type="button" class="btn btn-micv5 btn-block">确定</button></center>
						
                </section>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
	$(document).ready(function(){
		//教师来源
		$(document).on('click','.from',function(){
			//获取教师来源
			if($(this).attr("type")){
				var from_id=$(this).attr("type")
			}else{
				var from_id=0;
			}
			//获取教师职位
			if($('.positions').attr("type")){
				var position_id = $('.positions').attr("type")
			}else{
				var position_id = 0;
			}
			thiss = $(this);
			$.ajax({
				type : "get",
				url : "<?php echo Url::to(['teacher/teacher']);?>",
				data : 'from_id='+from_id+'&position_id='+position_id,
				success: function(msg){
					$("#div").html(msg)
					$('.froms').attr('class','from');
					thiss.attr('class','aH froms');
				}
			});
			return false;
		})
		//教师职位
		$(document).on('click','.position',function(){
			//获取教师来源
			if($(this).attr("type")){
				var position_id = $(this).attr("type")
			}else{
				var position_id = 0;
			}
			//获取教师职位
			if($('.froms').attr("type")){
				var from_id = $('.froms').attr("type")
			}else{
				var from_id = 0;
			}
			thiss = $(this);
			$.ajax({
				type : "get",
				url : "<?php echo Url::to(['teacher/teacher']);?>",
				data : 'from_id='+from_id+'&position_id='+position_id,
				success: function(msg){
					$("#div").html(msg)
					$('.positions').attr('class','position');
					thiss.attr('class','aH positions');
				}
			});
			return false;
		})
		//分页
		$(document).on('click','.pagination a',function(){
			var page = $(this).html()
			//获取教师来源
			if($(this).attr("type")){
				var position_id = $(this).attr("type")
			}else{
				var position_id = 0;
			}
			//获取教师职位
			if($('.froms').attr("type")){
				var from_id = $('.froms').attr("type")
			}else{
				var from_id = 0;
			}
			thiss = $(this);
			$.ajax({
				type : "get",
				url : "<?php echo Url::to(['teacher/teacher']);?>",
				data : 'from_id='+from_id+'&position_id='+position_id+'&page='+page,
				success: function(msg){
					$("#div").html(msg)
				}
			});
			return false;
		})
		//喜欢
		$(document).on('click','.like',function(){
			if($(this).attr("type")){
				var teacher_id = $(this).attr("type")
			}
			thiss = $(this);
			$.ajax({
				type : "get",
				url : "<?php echo Url::to(['teacher/teacherlike']);?>",
				data : 'teacher_id='+teacher_id,
				dataType : 'json',
				success: function(msg){
					if(msg.code == 1){
						//alert(msg.msg)
                        jq('#loginModal').modal('show');
					}else if(msg.code == 2){
                        //不能重复喜欢
						//alert(msg.msg)
                        jq('#likeTwice').modal('show');
					}else if(msg.code == 3){
						//喜欢成功
						thiss.replaceWith('<span class="like" type="'+teacher_id+'"><img src="<?php echo Url::to('@web/public/likes.png', true);?>" alt="" style="width: 30px;"/></span>')
						$('.like'+teacher_id).replaceWith("<font size='4px' class='like"+teacher_id+"'>喜欢： "+msg.data+" </font>")
					}else if(msg.code == 4){
						alert(msg.msg)
					}
				}
			});
		})
	});
</script>